<?php
namespace app\nadmin\controller;
use app\nadmin\model\LoginIpLog_M;
use think\Controller;
use think\facade\Session;

//use think\Hook;
class Index extends Base
{
    public function index()
    {
        //IP记录
        $ipArr = $this->getLoginIpLog();
        $newIp = $ipArr[0];

        $imInfo  = []; //IM系统尚未开放
        $this->assign('imInfo',$imInfo);
        $this->assign('adminInfo',$this->adminInfo);
        //var_dump($this->adminInfo);die;
        $this->assign('menuList',$this->getMenuList());
        $this->assign('ipArr',$ipArr);
        $this->assign('newIp',$newIp);
        return $this->fetch();
    }

    /*获取菜单列表*/
    protected function getMenuList()
    {
        //当前管理员id
        $id = $this->adminInfo['id'];

        return Session::get("menu_".$id);
    }

    //获取登陆IP记录 由于大部分操作都在框架集中操作，所以IP数据无需加入缓存
    protected function getLoginIpLog()
    {
        $loginIpLog_M = new LoginIpLog_M();
        $field = ['ip','ctime'];
        $where = "adminerId=$this->adminerId";
        $order = ['id'=>'desc'];
        $limit = 5;
        $re = $loginIpLog_M->getMore($field,$where,$order,$limit);
        foreach($re as &$v)
        {
            $v['ip'] = long2ip($v['ip']);
        }
        return $re;
    }
}
